package o;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.webkit.WebView;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appgallery.share.api.ShareBean;
import com.huawei.appmarket.service.exposure.bean.ExposureDetail;
import com.huawei.appmarket.service.webview.js.request.BatchAppDetailResponse;
import com.huawei.appmarket.service.webview.js.request.BatchAppDetailResponse$AppControlledInfo;
import com.huawei.appmarket.support.video.fullscreen.FullScreenVideoPlayProtocol;
import com.huawei.fastengine.fastview.NavigationUtils;
import com.huawei.hms.framework.network.restclient.dnkeeper.DNKeeperConfig;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
import o.der.f;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public abstract class ens {
    private static long ॱ = 0;

    static class a implements IServerCallBack {
        private WeakReference<WebView> ˋ;
        private String ˎ;

        public a(WebView webView, String str) {
            this.ˋ = new WeakReference(webView);
            this.ˎ = str;
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            if (dof.ॱ(this.ˎ)) {
                Logger.ˋ("JsHelper", "AppsControlledCallback callback null");
                return;
            }
            WebView webView = (WebView) this.ˋ.get();
            if (webView == null) {
                Logger.ˋ("JsHelper", "AppsControlledCallback webView null");
                return;
            }
            JSONArray jSONArray = new JSONArray();
            if (responseBean.getResponseCode() == 0 && responseBean.getRtnCode_() == 0 && (responseBean instanceof BatchAppDetailResponse)) {
                List<BatchAppDetailResponse$AppControlledInfo> ॱ = ((BatchAppDetailResponse) responseBean).ॱ();
                if (ॱ != null && ॱ.size() > 0) {
                    for (BatchAppDetailResponse$AppControlledInfo ˊ : ॱ) {
                        jSONArray.put(ens.ˏ(ˊ));
                    }
                }
            }
            String jSONArray2 = jSONArray.toString();
            if (Logger.ˎ()) {
                Logger.ˏ("JsHelper", "getAppsControlled result :" + jSONArray2);
            }
            webView.loadUrl("javascript:" + this.ˎ + "(" + jSONArray2 + ")");
        }
    }

    static class d {
        boolean ˋ = false;

        d() {
        }
    }

    ens() {
    }

    public static boolean ॱ(String str) {
        return (str == null || str.contains("<") || str.contains(">")) ? false : true;
    }

    public static void ॱ(Context context, String str, WebView webView, String str2) {
        try {
            JSONObject jSONObject = new JSONObject(str);
            String optString = jSONObject.optString("shareMethod");
            if ("Content".equals(optString)) {
                ˏ(context, jSONObject, webView, str2);
            } else if ("appName".equals(optString)) {
                ˊ(context, jSONObject);
            }
        } catch (JSONException e) {
            Logger.ˎ("js", "json Exception ");
        }
    }

    private static void ˏ(Context context, JSONObject jSONObject, WebView webView, String str) {
        String optString = jSONObject.optString("appId");
        String optString2 = jSONObject.optString("appIdType");
        Object optString3 = jSONObject.optString("title");
        Object optString4 = jSONObject.optString("content");
        Object optString5 = jSONObject.optString("pictureUrl");
        String optString6 = jSONObject.optString("shareUrl");
        int ˊ = ˊ(jSONObject);
        int ॱ = ॱ(jSONObject);
        String ˎ = ˎ(jSONObject);
        String ˋ = ˋ(jSONObject);
        ShareBean shareBean = new ShareBean();
        if (TextUtils.isEmpty(optString3) || TextUtils.isEmpty(optString4) || TextUtils.isEmpty(optString5)) {
            Logger.ˏ("JsHelper", "Some sharing parameters are missing!");
            return;
        }
        shareBean.ॱ(optString4);
        shareBean.ˎ(optString3);
        shareBean.ˋ(optString5);
        shareBean.ˊ(context.getResources().getIdentifier(context.getString(f.ˊˈ), "drawable", context.getPackageName()));
        shareBean.ˏ(ˋ);
        shareBean.ʼ(ˎ);
        shareBean.ˏ(ˊ);
        shareBean.ˋ(ॱ);
        shareBean.ʽ(2);
        shareBean.ʽ(optString);
        shareBean.ॱॱ(optString2);
        if (TextUtils.isEmpty(optString6)) {
            optString6 = enx.ˎ(str);
            if (TextUtils.isEmpty(optString6)) {
                ((Activity) context).runOnUiThread(new eni(webView, str, shareBean));
                return;
            }
        }
        shareBean.ˊ(baa.ˏ(optString6));
        ((cww) fho.ˏ().ˋ("Share").ॱ(cww.class)).ˎ(context, shareBean);
    }

    private static void ˊ(Context context, JSONObject jSONObject) {
        String optString = jSONObject.optString("appId");
        String optString2 = jSONObject.optString("appName");
        String string = context.getString(f.ˊˉ);
        if (TextUtils.isEmpty(optString2)) {
            Logger.ˏ("JsHelper", "Some sharing parameters are missing!");
            return;
        }
        string = context.getResources().getIdentifier(string, "string", context.getPackageName()) + optString2;
        optString2 = String.format(Locale.ENGLISH, context.getResources().getString(f.ˑˋ), new Object[]{"\"" + optString2 + "\""});
        StringBuilder stringBuilder = new StringBuilder(DnsConfig.MAX_CACHE_ENTRIES);
        stringBuilder.append(optString2);
        stringBuilder.append(";ID:");
        stringBuilder.append(optString);
        Intent intent = new Intent("android.intent.action.SEND");
        intent.setType(DNKeeperConfig.DNKEEPER_CONTENT_TYPE);
        intent.putExtra("android.intent.extra.SUBJECT", string);
        intent.putExtra("android.intent.extra.TEXT", stringBuilder.toString());
        ˎ(context, Intent.createChooser(intent, context.getResources().getString(f.ˎﹳ)));
    }

    private static int ˊ(JSONObject jSONObject) {
        int i = 1;
        if (jSONObject.has("shareType")) {
            try {
                i = jSONObject.getInt("shareType");
            } catch (JSONException e) {
                Logger.e("JsHelper", "can not get ShareType");
            }
        }
        return i;
    }

    private static String ˎ(JSONObject jSONObject) {
        String str = "";
        if (jSONObject.has("sharePkg")) {
            try {
                str = jSONObject.getString("sharePkg");
            } catch (JSONException e) {
                Logger.e("JsHelper", "can not get ShareType");
            }
        }
        return str;
    }

    private static String ˋ(JSONObject jSONObject) {
        String str = "award";
        if (jSONObject.has("shareFromWhere")) {
            try {
                str = jSONObject.getString("shareFromWhere");
            } catch (JSONException e) {
                Logger.e("JsHelper", "can not get ShareType");
            }
        }
        return str;
    }

    private static int ॱ(JSONObject jSONObject) {
        int i = -1;
        if (jSONObject.has("shareFlag")) {
            try {
                i = jSONObject.getInt("shareFlag");
            } catch (JSONException e) {
                Logger.e("JsHelper", "can not get ShareFlag");
            }
        }
        return i;
    }

    private static void ˎ(Context context, Intent intent) {
        if (!(context instanceof Activity)) {
            intent.setFlags(268435456);
        }
        context.startActivity(intent);
    }

    static void ॱ(Context context, String str, String str2, String str3) {
        cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
        Request request = new Request(str, null);
        if (!dof.ˋ(str2)) {
            request.ᐝ(str2);
        }
        if (!dof.ˋ(str3)) {
            request.ʻ(str3);
        }
        appDetailActivityProtocol.ˏ(request);
        cjk.ˎ().ˋ(context, new cjm("appdetail.activity", appDetailActivityProtocol));
    }

    public static void ˊ(Context context, String str) {
        if (!dof.ॱ(str) && Pattern.compile("^[0-9]{5,15}$").matcher(str).matches()) {
            Intent intent = new Intent("android.intent.action.DIAL", Uri.parse(NavigationUtils.TEL_SCHEMA_PREF + str));
            intent.setFlags(268435456);
            context.startActivity(intent);
        }
    }

    public static void ˏ(Context context, String str, String str2) {
        if (TextUtils.isEmpty(str2) || TextUtils.isEmpty(str)) {
            Logger.e("JsHelper", "URL or html is empty.");
            return;
        }
        try {
            byte[] ˎ = dnk.ˎ(str2);
            if (ˎ == null) {
                Logger.e("JsHelper", "URL is null after Decode.");
                return;
            }
            env ˏ = enw.ˏ(new String(ˎ, "UTF-8"), str);
            if (dok.ͺ()) {
                ˋ(context, ˏ);
            } else {
                evk.ˋ(context, context.getString(f.ʻʽ), 0).ˋ();
            }
        } catch (Exception e) {
            Logger.e("JsHelper", "showMenuDialog error");
        }
    }

    private static void ˋ(Context context, env o_env) {
        String ˏ = enx.ˏ(o_env.ॱ());
        ShareBean shareBean = new ShareBean();
        shareBean.ॱ(o_env.ˊ() != null ? o_env.ˊ() : "");
        shareBean.ˎ(o_env.ˏ());
        shareBean.ˋ(o_env.ˋ());
        shareBean.ˏ(o_env.ʻ());
        shareBean.ˋ(o_env.ˎ());
        shareBean.ˊ(context.getResources().getIdentifier(context.getString(f.ˊˈ), "drawable", context.getPackageName()));
        shareBean.ˊ(ˏ);
        shareBean.ˏ("");
        shareBean.ˎ(true);
        shareBean.ʽ(1);
        ((cww) fho.ˏ().ˋ("Share").ॱ(cww.class)).ˎ(context, shareBean);
    }

    public static void ˊ(Context context, String str, int i) {
        long currentTimeMillis = System.currentTimeMillis();
        if (Math.abs(currentTimeMillis - ॱ) >= 1000) {
            ॱ = currentTimeMillis;
            if (!TextUtils.isEmpty(str)) {
                if (doo.ˊ(context)) {
                    cjo fullScreenVideoPlayProtocol = new FullScreenVideoPlayProtocol();
                    FullScreenVideoPlayProtocol.Request request = new FullScreenVideoPlayProtocol.Request();
                    request.ˎ(str);
                    request.ˊ(i);
                    fullScreenVideoPlayProtocol.ˊ(request);
                    cjm o_cjm = new cjm("fullscreenvideoplay.activity", fullScreenVideoPlayProtocol);
                    if (!(context instanceof Activity)) {
                        o_cjm.ॱ(context).addFlags(268435456);
                    }
                    cjk.ˎ().ˋ(context, o_cjm);
                    return;
                }
                evk.ˏ(context.getString(f.ʻʽ));
            }
        }
    }

    public static void ˋ(Context context, String str, String str2, String str3) {
        if (TextUtils.isEmpty(str2) || TextUtils.isEmpty(str)) {
            Logger.e("JsHelper", "URL or html is empty.");
        } else if (TextUtils.isEmpty(str3)) {
            Logger.e("JsHelper", "jsonString is empty.");
        } else {
            try {
                byte[] ˎ = dnk.ˎ(str2);
                if (ˎ == null) {
                    Logger.e("JsHelper", "URL is null after Decode.");
                    return;
                }
                env ˋ = enw.ˋ(new String(ˎ, "UTF-8"), str);
                if (dok.ͺ()) {
                    ShareBean shareBean = new ShareBean();
                    shareBean.fromJson(new JSONObject(str3));
                    int ॱˊ = shareBean.ॱˊ();
                    if (2 == ॱˊ || 3 == ॱˊ) {
                        shareBean.ˊ(enx.ˏ(ˋ.ॱ()));
                        ((cww) fho.ˏ().ˋ("Share").ॱ(cww.class)).ˎ(context, shareBean);
                        return;
                    }
                    Logger.ˏ("JsHelper", "wapShareType: " + ॱˊ);
                    return;
                }
                evk.ˋ(context, context.getString(f.ʻʽ), 0).ˋ();
            } catch (Exception e) {
                Logger.e("JsHelper", "showShareDialog error");
            }
        }
    }

    public static void ˎ(Context context, String str) {
        if (context != null && !dof.ॱ(str)) {
            int ॱ = ccz.ॱ();
            if (context instanceof Activity) {
                ॱ = dgm.ˎ((Activity) context);
            }
            dyg ॱ2 = dyg.ॱ();
            ExposureDetail ˎ = ExposureDetail.ˎ(str);
            if (ˎ != null) {
                ॱ2.ˎ(ˎ, ॱ);
            }
            new dyf().ˊ(ॱ2, ॱ);
        }
    }

    public static void ˎ(WebView webView, String str, String str2) {
        cfw.ˎ(enu.ॱ(str, 1), new a(webView, str2));
    }

    private static JSONObject ˏ(BatchAppDetailResponse$AppControlledInfo batchAppDetailResponse$AppControlledInfo) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("appId", batchAppDetailResponse$AppControlledInfo.ˏ());
            jSONObject.put("isControlled", ˋ(batchAppDetailResponse$AppControlledInfo.ˋ()));
        } catch (Exception e) {
            Logger.ˋ("JsHelper", "createAppsControlledResult json error");
        }
        return jSONObject;
    }

    private static int ˋ(int i) {
        if (i == 1 || i == 2 || i == 3) {
            return 1;
        }
        return 0;
    }
}
